home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World Komputer 2010 April
/
PCWorld0410.iso
/
pluginy Firefox
/
56194
/
56194.xpi
/
chrome
/
topsite.jar
/
content
/
js
/
dal.js
< prev
next >
Wrap
Text File
|
2010-01-14
|
11KB
|
247 lines
if (!topsite.dal) topsite.dal = {};
topsite.dal = {
serverUrl: "http://similarnet.com/similarweb/TopSitesWebGetService.svc",
lb1Url: "http://similarnet.com/LoadBalancer/Main.asmx",
lb2Url: "",
serverSessionId: "TF12345678",
initialized: false,
init: function(){
if (topsite.dal.initialized)
return;
try{
topsite.dal.lb2Url = topsite.common.prefManager.getCharPref(topsite.consts.PREF_SECOND_LB);
}catch(e){}
if (topsite.dal.lb2Url){
topsite.dal.getDataUrl();
}else{
topsite.dal.getLb2Url();
}
},
getLb2Url: function(){
var myVersion = topsite.common.getAddonVersion();
var params = "";
params += "<?xml version=\"1.0\" encoding=\"utf-8\"?>";
params += "<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap=\"http://www.w3.org/2003/05/soap-envelope\">";
params += "<soap:Body>";
params += "<FirstTimeGetConnectionDetails xmlns=\"Search.SimilarWeb.com/ConnectFirstTime\">";
params += "<request>";
params += "<VersionNumber>" + myVersion + "</VersionNumber>";
params += "</request>";
params += "</FirstTimeGetConnectionDetails>";
params += "</soap:Body>";
params += "</soap:Envelope>";
var action = "Search.SimilarWeb.com/ConnectFirstTime/FirstTimeGetConnectionDetails";
topsite.dal.QueryToSoap(topsite.dal.lb1Url, params, action, topsite.dal.getSecondLBResponse);
},
getSecondLBResponse: function(responseXML){
topsite.dal.lb2Url = responseXML.getElementsByTagName("ServerDetails")[0].firstChild.nodeValue;
if (topsite.dal.lb2Url){
topsite.common.prefManager.setCharPref(topsite.consts.PREF_SECOND_LB, topsite.dal.lb2Url);
topsite.dal.getDataUrl();
}
},
getDataUrl: function(){
var myVersion = topsite.common.getAddonVersion();
var params = "";
params += "<?xml version=\"1.0\" encoding=\"utf-8\"?>";
params += "<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap=\"http://www.w3.org/2003/05/soap-envelope\">";
params += "<soap:Body>";
params += "<GetConnectionDetails xmlns=\"Search.SimilarWeb.com/Connect\">";
params += "<request>";
params += "<VersionNumber>" + myVersion + "</VersionNumber>";
params += "</request>";
params += "</GetConnectionDetails>";
params += "</soap:Body>";
params += "</soap:Envelope>";
var action = "Search.SimilarWeb.com/Connect/GetConnectionDetails";
topsite.dal.QueryToSoap(topsite.dal.lb2Url, params, action, topsite.dal.getDataWsResponse);
},
getDataWsResponse: function(responseXML){
topsite.dal.serverUrl = responseXML.getElementsByTagName("ServerDetails")[0].firstChild.nodeValue;
topsite.dal.serverUrl = topsite.dal.serverUrl.substring(0, topsite.dal.serverUrl.lastIndexOf("/") + 1) + "TopSitesWebGetService.svc";
topsite.dal.serverSessionId = responseXML.getElementsByTagName("SessionID")[0].firstChild.nodeValue;
},
getTopicsForUrl: function(strUrl, prevUrl, navType, isFromLink, cancelAdv, callback, paramsForCallback){
var topicsFromCache = this.getTopicsFromCache(strUrl);
if (topicsFromCache != null){
callback(topicsFromCache, paramsForCallback);
return;
}
topsite.dal.getTopicsFromServer(strUrl, prevUrl, navType, isFromLink, cancelAdv, callback, paramsForCallback);
},
getTopSiteForTopic: function(strTopic, strUrl, callback, paramsForCallback){
var topSiteFromCache = this.getTopSiteFromCache(strTopic, strUrl);
if (topSiteFromCache != null){
callback(topSiteFromCache, paramsForCallback);
return;
}
topsite.dal.getTopSiteFromServer(strTopic, strUrl, callback, paramsForCallback);
},
getTopicsFromServer: function(strUrl, prevUrl, navType, isFromLink, cancelAdv, callback, paramsForCallback){
var params = "";
params += "NewSite=" + escape(strUrl) + "&";
params += "SessionID=" + this.serverSessionId + "&";
params += "GSessionID=" + topsite.common.getGSessionId() + "&";
params += "IsLink=" + isFromLink + "&";
if (cancelAdv)
params += "AdvType=-1&";
params += "NavigatedType=" + navType + "&";
params += "PreviousSite=" + escape(prevUrl) + "&";
params += "SourceID=500";
topsite.dal.QueryToSimpleXml(topsite.dal.serverUrl + "/GetTopics", params, topsite.dal.getTopicsResponse, callback, paramsForCallback, strUrl);
},
getTopSiteFromServer: function(strTopic, strCurrUrl, callback, paramsForCallback){
var params = "";
params += "Topic=" + escape(strTopic) + "&";
params += "GSessionID=" + topsite.common.getGSessionId() + "&";
params += "SessionID=" + topsite.dal.serverSessionId + "&";
params += "Url=" + escape(strCurrUrl) + "&";
params += "SourceID=500&";
params += "NavigatedType=501";
var arrTopicUrl = new Array(2);
arrTopicUrl[0] = strTopic;
arrTopicUrl[1] = strCurrUrl;
topsite.dal.QueryToSimpleXml(topsite.dal.serverUrl + "/GetTopSites", params, topsite.dal.getTopSiteResponse, callback, paramsForCallback, arrTopicUrl);
},
getTopicsResponse: function(responseXML, callback, paramsForCallback, strUrl){
var arrTopicElements = responseXML.firstChild.childNodes;
var arrTopicsForUrl = new Array(arrTopicElements.length);
for (var i = 0; i < arrTopicElements.length; ++i){
arrTopicsForUrl[i] = arrTopicElements[i].firstChild.nodeValue;
}
callback(arrTopicsForUrl, paramsForCallback);
topsite.dal.setTopicsToCache(strUrl, arrTopicsForUrl);
},
getTopSiteResponse: function(responseXML, callback, paramsForCallback, arrTopicUrl){
var arrUrlElements = responseXML.firstChild.childNodes;
var arrUrlsForTopic = new Array(arrUrlElements.length);
for (var i = 0; i < arrUrlElements.length; ++i){
arrUrlsForTopic[i] = new Array(3);
arrUrlsForTopic[i][0] = arrUrlElements[i].getElementsByTagName("Url")[0].firstChild.nodeValue;
arrUrlsForTopic[i][1] = arrUrlsForTopic[i][0];
arrUrlsForTopic[i][2] = false;
if (arrUrlElements[i].getElementsByTagName("NavigateUrl").length>0 && arrUrlElements[i].getElementsByTagName("NavigateUrl")[0].firstChild && arrUrlElements[i].getElementsByTagName("NavigateUrl")[0].firstChild.nodeValue){
arrUrlsForTopic[i][1] = arrUrlElements[i].getElementsByTagName("NavigateUrl")[0].firstChild.nodeValue;
arrUrlsForTopic[i][2] = true;
}
}
callback(arrUrlsForTopic, paramsForCallback);
topsite.dal.setTopSiteToCache(arrTopicUrl[0], arrTopicUrl[1], arrUrlsForTopic);
},
getTopicsFromCache: function(strUrl){
// TODO: implement
return null;
},
getTopSiteFromCache: function(strTopic, strUrl){
// TODO: implement
return null;
},
setTopicsToCache: function(strUrl, arrTopicsForUrl){
// TODO: implement
},
setTopSiteToCache: function(strTopic, strUrl, arrSitesForTopic){
// TODO: implement
},
QueryToSoap: function(url, soapParams, soapAction, innerCallback, callback, paramsForCallback, innerParams){
var http = new XMLHttpRequest();
http.open("POST",url,true);
if (http.channel instanceof Components.interfaces.nsISupportsPriority){
// Set the priority to lower (positive is lower)
http.channel.adjustPriority(999);
}
http.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
http.setRequestHeader("Content-Length", soapParams.length);
http.setRequestHeader("SOAPAction", soapAction);
var httpAborted = false;
var requestTimer = setTimeout(function() {
httpAborted = true;
http.abort();
}, 3000);
http.onreadystatechange = function handleResponse(){
if(http.readyState==4){
clearTimeout(requestTimer);
var status = http.status;
if(status==200){
innerCallback(http.responseXML, callback, paramsForCallback, innerParams);
}
else{
// Request with no response
if (status!=202){
// TODO: handle error
}
}
}
}
http.send(soapParams);
},
QueryToSimpleXml: function(url, params, innerCallback, callback, paramsForCallback, innerParams){
var http = new XMLHttpRequest();
http.open("GET",url + "?" + params,true);
if (http.channel instanceof Components.interfaces.nsISupportsPriority){
// Set the priority to lower (positive is lower)
http.channel.adjustPriority(999);
}
var httpAborted = false;
var requestTimer = setTimeout(function() {
httpAborted = true;
http.abort();
}, 3000);
http.onreadystatechange = function handleResponse(){
if(http.readyState==4){
clearTimeout(requestTimer);
var status = http.status;
if(status==200){
innerCallback(http.responseXML, callback, paramsForCallback, innerParams);
}
else{
// Request with no response
if (status!=202){
// TODO: handle error
}
}
}
}
http.send(null);
}
};